package ua.com.shkil.jxui.notification;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Timer;

import ua.com.shkil.jxui.notification.Notification;
import ua.com.shkil.jxui.notification.NotificationFrame;
import ua.com.shkil.jxui.notification.NotificationModel;
import ua.com.shkil.jxui.notification.NotificationPanel;
import ua.com.shkil.jxui.notification.SimpleNotification;
import ua.com.shkil.jxui.notification.NotificationModel.NotificationModelListener;

public class Sample {

	public static void main(String[] args) {
		new Sample().run();
	}

	NotificationModel model = new NotificationModel();
	NotificationPanel panel = new NotificationPanel(model);
	NotificationFrame frame = new NotificationFrame(panel);
	Timer timer;

	public void run() {
		panel.setMaxVisibleCount(3);
		frame.setVisible(true);
		timer = new Timer(2000, new ActionListener() {
			private int number;
			@Override
			public void actionPerformed(ActionEvent e) {
				if (number > 7) {
					timer.stop();
				}
				model.add(new SimpleNotification(SimpleNotification.TYPE_PLAIN, "Notification " + ++number));
			}
		});
		timer.start();
		model.addNotificationModelListener(new NotificationModelListener() {
			@Override
			public void notificationAdded(Notification notif) {
				System.out.println(".notificationAdded()");
			}
			@Override
			public void notificationModelChanged(NotificationModel model) {
				System.out.println(".notificationModelChanged()");
			}
			@Override
			public void notificationRemoved(Notification notif) {
				System.out.println(".notificationRemoved()");
				if (model.count() == 0) {
					System.exit(0);
				}
			}
		});
		model.add(new SimpleNotification(SimpleNotification.TYPE_WARNING, "Test started"));
	}

}
